﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using INTEX.DataBase.Tools;
using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core.Events;
using ReflectionStudio.Core.Helpers;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for ProductionOrder.xaml
    /// </summary>
    public partial class JLTBB07 : DocumentBase
    {
        #region-------------Properties-----------------------

        JLTBB07Data m_Data,m_DataX;
        ITXEXRPT ITXEXRPT;
        public ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        INTEXDBC INTEXDBC
        {
            get
            {
                return app.INTEXDBC;
            }
        }
        public INTEXBL INTEXBL
        {
            get
            {
                return app.INTEXBL;
            }
        }/*
        public SETINTEXDB SetData
        {
            get
            {
                return (SETINTEXDB)TryFindResource("SetData");
            }
        }
        public SETINTEXDB SetDetail
        {
            get
            {
                return (SETINTEXDB)TryFindResource("SetDetail");
            }
        }
        public SETINTEXDB SetEnv
        {
            get
            {
                return (SETINTEXDB)TryFindResource("SetEnv");
            }
        }*/
        /*#region=====vwMaster=======
        CollectionViewSource vwMaster
        {
            get
            {
                return (CollectionViewSource)this.TryFindResource("vwMaster");
            }
        }
        DataRow dwMaster
        {
            get
            {
                if (vwMaster.View == null)
                    return null;
                if ((DataRowView)vwMaster.View.CurrentItem == null)
                    return null;
                return ((DataRowView)vwMaster.View.CurrentItem).Row;
            }
        }
        #endregion
        #region=====vwARANS=======
        CollectionViewSource vwMU
        {
            get
            {
                return (CollectionViewSource)this.TryFindResource("vwMU");
            }
        }
        DataRow dwMU
        {
            get
            {
                if (vwMU.View == null)
                    return null;
                if ((DataRowView)vwMU.View.CurrentItem == null)
                    return null;
                return ((DataRowView)vwMU.View.CurrentItem).Row;
            }
        }
        #endregion
        #region=====  vwYGAAUF=======
        CollectionViewSource vwYGAAUF
        {
            get
            {
                return (CollectionViewSource)this.TryFindResource("vwYGAAUF");
            }
        }
        DataRow dwYGAAUF
        {
            get
            {
                if (vwYGAAUF.View == null)
                    return null;
                if ((DataRowView)vwYGAAUF.View.CurrentItem == null)
                    return null;
                return ((DataRowView)vwYGAAUF.View.CurrentItem).Row;
            }
        }
        #endregion
      
    
  

        BindingListCollectionView cvMGAAUF
        {
            get
            {
                return (BindingListCollectionView)CollectionViewSource.GetDefaultView(this.dlgMGAAUF.ItemsSource);
            }
        }*/
 
        #endregion
        private Dictionary<string, object> dicParamater;
        public DataSet dsResult;
        public DataSet setUI = new DataSet();
        public DataSet dsParamaters;
        private DataRow dwUI;
        public DataRow dwGASTGA;
        DataTable tableUI;
        private string fromdate = "", enddate = "";
        public string ARTICLE = "", COLORNO = "";
        public JLTBB07()
        {
            InitializeComponent();
            this.Name = "浆纱出轴报表";
            m_Data = new JLTBB07Data();
            ITXEXRPT = new ITXEXRPT();
            ITXEXRPT.Root = "C:\\IntexReport";
            ITXEXRPT.PrintType = "OpenExcel";   

        }
        public override void SetUp(Dictionary<string, object> dicParamater)
        {
            base.SetUp(dicParamater);
            InitializeComponent();
            this.dicParamater = dicParamater;
            base.SetUp(dicParamater);
            InitializeComponent();
            m_Data = new JLTBB07Data();
            tableUI = new DataTable("UIData");
            tableUI.Columns.Add("CO", typeof(string));
            tableUI.Columns.Add("FROMDATE", typeof(string));
            tableUI.Columns.Add("ENDDATE", typeof(string));

        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                dwUI = tableUI.NewRow();
                txtCO.Focus();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return;

        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            try
            {
                using (new LongOperation(this, "读取符合条件的记录"))
                {
                    DataSet setResult = new DataSet();
                    setUI.Clear();
                    setUI.AcceptChanges();
                    string CO = txtCO.Text.Trim();
                   
                    if(fromdate=="")
                    {
                        fromdate = "20000000";
                    }
                    if (enddate == "")
                    {
                        enddate = "99999999";
                    }

                    dwUI["CO"] = CO;
                    dwUI["FROMDATE"] = fromdate;
                    dwUI["ENDDATE"] = enddate;
                    setResult = m_Data.BuildData(dwUI);
                    setUI.Merge(setResult);
                    MasterDg.DataContext = setUI.Tables["BB07"];
                }

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void btnEXCEL_Click(object sender, RoutedEventArgs e)
        {
            
            try
            {
                
                m_DataX = new JLTBB07Data(dicParamater);
                m_DataX.exAgent._app.Visible = false;
                m_DataX.OracleDB = INTEXDBC.OracleDB;
                m_DataX.proxy = INTEXDBC.proxy;
                JLTBB07Report m_rpt = new JLTBB07Report(dicParamater);
                m_rpt.dsSource = setUI;
                m_rpt.PrintType = "OpenExcel";
                m_rpt.exAgent = m_DataX.exAgent;
                m_rpt.WriteExcelReport("OpenExcel");
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }
        private void txtART_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                btnQuery_Click(null, null);
            }
        }
        private void FROM_DATE_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                fromdate = "";
                fromdate = m_Data.GetDate(sender);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }
        private void END_DATE_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                enddate = "";
                enddate = m_Data.GetDate(sender);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }

        /*private void MasterDg_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (e.AddedItems.Count == 0)
                    return;
                DataRowView drv = e.AddedItems[0] as DataRowView;
                dwGASTGA = drv.Row;
                DataSet setResult = new DataSet();
                if (setUI.Tables.Contains("BOM"))
                {
                    setUI.Tables.Remove("BOM");
                    setUI.AcceptChanges();
                }
                setResult = m_Data.GetBOM(dwGASTGA);
                setUI.Merge(setResult);
                dlDg.DataContext = setUI.Tables["BOM"];

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }*/
    }
}